import { createSlice } from "@reduxjs/toolkit";
import { RootState } from "../store";


export interface LanguageState {
    language: "en" | "zh";
    languageList: { name: string; code: string }[];
  }
  
  const initialState: LanguageState = {
    language: "zh",
    languageList: [
      { name: "中文", code: "zh" },
      { name: "English", code: "en" },
    ],
  };
  
  export const languageSlice = createSlice({
      name: 'language',
      initialState,
      reducers: {
          changeLanguage(state, action) {
              state.language = action.payload;
          },
          addLanguage(state, action) {
            state.languageList = [...state.languageList, action.payload];
          }
      }
  });

  export const selectLanguage = (state: RootState) => state.language.language;
